
class Node:
    """ 节点 """

    def __init__(self, value):
        self.value = value
        self.next = next


class SingleLinkList(object):
    """ 单链表 """

    def __init__(self, node=None):
        self.__head = node

    def is_empty(self):
        return self.__head == None

    def length(self):
        """ 链表长度 """
        cur = self.__head
        count = 0
        while cur != None:
            count += 1
            cur = cur.next
        return count

    def printAll(self):
        """ 打印链表中所有值 """
        cur = self.__head
        while cur != None:
            print(cur.value, end='\t')
            cur = cur.next
        print()

    def is_has_cycle(self, head):
        """ 链表中是否有环 """
        slow = fast = head
        while slow and fast and fast.next:
            slow = slow.next
            fast = fast.next.next
            if slow is fast:
                return True
        return False

    def reverse(self, head):
        cur, prev = head, None
        while cur:
            cur.next, prev, cur = prev, cur, cur.next
        return prev
